/*
 * Copyright (c) 2011-2018, Meituan Dianping. All Rights Reserved.
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#ifndef PROJECT_ROUTE_BASE_H
#define PROJECT_ROUTE_BASE_H
#include <string>
#include <muduo/base/Mutex.h>
namespace meituan_mns {

class IDC {
 public:
  void CalculateIpMask(void);

  IDC() : region_(""),
          idc_(""),
          center_ (""),
          ip_ (""),
          mask_(""),
          int_mask_(0),
          ip_mask_value_(0) {}

  void SetRegion(const std::string &val);
  std::string GetRegion(void) const;

  void SetIdc(const std::string &val);
  std::string GetIdc(void) const;

  void SetCenter(const std::string &val);
  std::string GetCenter(void) const;

  void SetIp(const std::string &val);
  std::string GetIp(void) const;

  void SetMask(const std::string &val);
  std::string GetMask(void) const;

  bool IsSameIdc(const std::string &ip);

 private:
  int32_t ConvertMaskToInt(void);
  int32_t GetIp4Value(const std::string &ip);

 private:
  std::string region_;
  std::string idc_;
  std::string center_;
  std::string ip_;
  std::string mask_;

  int32_t int_mask_;
  int32_t ip_mask_value_;

};
}

#endif //PROJECT_ROUTE_BASE_H
